﻿using System;
using Thrift.Protocol;
using Thrift.Transport;

namespace Inovout.Data.HBase
{
    public class HBaseConnection : IDisposable
    {
        private TTransport transport;
        private TProtocol protocol;
        internal Hbase.Client Client { get; private set; }
        public HBaseConnection(string ip, int port)
        {
            transport = new TSocket(ip, port);
            protocol = new TBinaryProtocol(transport);
            Client = new Hbase.Client(protocol);
        }
        public void Open()
        {
            transport.Open();
        }
        public TableCommand CreateTableCommand()
        {
            return CreateCommand<TableCommand>();
        }
        private TCommand CreateCommand<TCommand>() where TCommand : HBaseCommand, new()
        {
            TCommand command = new TCommand();
            command.Connection = this;
            return command;
        }

        public void Dispose()
        {
            transport.Close();
            transport.Dispose();
        }
    }
}
